package ch08;

class ExceptionEx19 {
	public static void main(String args[]) {
		try {
			startInstall();
			copyFiles();
		} catch (SpaceException e)	{
			System.out.println("error message: " + e.getMessage());
			e.printStackTrace();
			System.out.println("retry to install in free space.");
		} catch (MemoryException me)	{
			System.out.println("error message: " + me.getMessage());
			me.printStackTrace();
			System.gc();
			System.out.println("retry to install.");
		} finally {
			deleteTempFiles();
		}
	}

   static void startInstall() throws SpaceException, MemoryException { 
		if(!enoughSpace())
			throw new SpaceException("lack of space.");
		if (!enoughMemory())
			throw new MemoryException("lack of memory.");
   }

   static void copyFiles() { }
   static void deleteTempFiles() { }
   
   static boolean enoughSpace()   {
		return false;
   }
   static boolean enoughMemory() {
		return true;
   }
}

class SpaceException extends RuntimeException {
	SpaceException(String msg) {
	   super(msg);	
   }
} 

class MemoryException extends RuntimeException {
	MemoryException(String msg) {
	   super(msg);	
   }
}
/*
error message: lack of space.
ch08.SpaceException: lack of space.
	at ch08.ExceptionEx20.startInstall(ExceptionEx20.java:23)
	at ch08.ExceptionEx20.main(ExceptionEx20.java:5)
retry to install in free space.
*/